//
//  TDCalendaViewShowC.m
//  TBRentClient
//
//  Created by tonbright on 2018/6/7.
//  Copyright © 2018年 tonbright. All rights reserved.
//

#import "TDCalendaViewShowC.h"
#import "YXDateHelpObject.h"
#import <FSCalendar.h>

#import "TDDiyShowCalehdaCell.h"
#import "TDCalendaShowModel.h"

#import "TDCalendaAlertPickC.h"
#import "NetWorkRequest.h"
@interface TDCalendaViewShowC()<FSCalendarDataSource,FSCalendarDelegate,FSCalendarDelegateAppearance>

@property (weak, nonatomic) FSCalendar *calendar;


@property (strong, nonatomic) NSCache *cache;
@property (assign, nonatomic) BOOL showsEvents;


@property (strong, nonatomic) NSCalendar *gregorian;
@property (strong, nonatomic) NSDateFormatter *dateFormatter;

@property (strong, nonatomic) NSDate *minimumDate;
@property (strong, nonatomic) NSDate *maximumDate;

@property (weak, nonatomic) IBOutlet UILabel *lbe_getCarDes;

@property (weak, nonatomic) IBOutlet UILabel *lbe_getCarDetail;

@property (weak, nonatomic) IBOutlet UIView *bottomView_getCar;

@property (weak, nonatomic) IBOutlet UILabel *lbe_rebackCarDes;
@property (weak, nonatomic) IBOutlet UILabel *lbe_rebackCarDetail;
@property (weak, nonatomic) IBOutlet UIView *bottomVIew_rebackCar;

@property (nonatomic, assign) NSInteger selIndex;//记录哪一个被点中  默认进页面额时候选中开始时间

@property (nonatomic,strong)NSDate *startSelDate;//开始选中日期
@property (nonatomic,strong)NSDate *endSelDate;//结束选中日期

@property (nonatomic,copy)NSString *topShowStartTitleStr;//顶部展示的字符串---------
@property (nonatomic,copy)NSString *topShowEndTitleStr;//顶部展示的字符串---------


@property (nonatomic,strong)NSArray *schedulelist;//选择起始时间后的 可用日期

@property (nonatomic, assign) BOOL shouldSel;
@property (nonatomic,strong)NSMutableArray *tmpAllArray;
@property (nonatomic,strong)NSMutableDictionary *tmpAllArrayDic;//设置状态的
@property (nonatomic,strong)NSMutableDictionary *tmpAllArrayReturnDic;//设置可还车的



@property (nonatomic,strong)NSMutableDictionary *allSchedulelistPriceDic;
@property (nonatomic,strong)NSMutableDictionary *allSchedulelistStatusDic;
@property (nonatomic,strong)NSMutableDictionary *allSchedulelistPicStatusDic;

@property (nonatomic,strong)NSMutableDictionary *schedulelistPriceDic;//选择起始时间后的 可用日期
@property (nonatomic,strong)NSMutableDictionary *schedulelistStatusDic;//选择起始时间后的 可用日期
@property (nonatomic,strong)NSMutableDictionary *schedulelistReturnStatusDic;//选择起始时间后的 可用日期

@end

@implementation TDCalendaViewShowC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadData];
    [self setupCalendar];
    self.shouldSel = NO;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
    
}

- (IBAction)backBtnClick:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)setupCalendar {
    FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(10, 145, Width - 20, Height - 190)];
    calendar.backgroundColor = [UIColor whiteColor];
    calendar.dataSource = self;
    calendar.delegate = self;
    calendar.pagingEnabled = NO; // important
    calendar.allowsMultipleSelection = YES;
    calendar.placeholderType = 0;//FSCalendarPlaceholderTypeFillHeadTail;
    calendar.locale = [NSLocale localeWithLocaleIdentifier:@"zh-CN"];
    calendar.appearance.caseOptions = FSCalendarCaseOptionsWeekdayUsesSingleUpperCase|FSCalendarCaseOptionsHeaderUsesUpperCase;
    calendar.placeholderType = FSCalendarPlaceholderTypeNone;
    calendar.today = nil;
    //    calendar.appearance.headerMinimumDissolvedAlpha = 0;
    calendar.appearance.caseOptions = FSCalendarCaseOptionsHeaderUsesUpperCase;
    calendar.appearance.caseOptions = FSCalendarCaseOptionsWeekdayUsesSingleUpperCase|FSCalendarCaseOptionsHeaderUsesDefaultCase;
    //    @property (strong, nonatomic) NSString *headerDateFormat;
    calendar.appearance.weekdayTextColor = [UIColor blackColor];
    calendar.appearance.headerTitleColor = [UIColor blackColor];
    
    [self.view addSubview:calendar];
    self.calendar = calendar;
    [calendar registerClass:[TDDiyShowCalehdaCell class] forCellReuseIdentifier:@"cell"];

    self.dateFormatter = [[NSDateFormatter alloc] init];
    self.dateFormatter.dateFormat = @"yyyy-MM-dd";
    self.minimumDate = [NSDate date];
    
//    self.maximumDate = [self.dateFormatter dateFromString:@"2019-04-10"];
    NSDate *maxDate = [[YXDateHelpObject manager] getEarlyOrLaterDate:[NSDate date] LeadTime:6 Type:1];
    self.maximumDate = maxDate;
}

// MARK: - 选择选中或则取消状态--------
- (void)chooseHourMinDate:(NSDate *)date {
    self.shouldSel = NO;
    __weak typeof(self) weakSelf = self;
    //最后点击的是取消还是选中状态
    TDCalendaAlertPickC *calendaAlertPickC = [[TDCalendaAlertPickC alloc] init];
    if (self.selIndex == 1) {
        calendaAlertPickC.hourIndex = [AppSetting shareAppSetting].endCalendaHourIndex;
        calendaAlertPickC.minIndex = [AppSetting shareAppSetting].endCalendaMinIndex;
    }else {
        calendaAlertPickC.hourIndex = [AppSetting shareAppSetting].startCalendaHourIndex;
        calendaAlertPickC.minIndex = [AppSetting shareAppSetting].startCalendaMinIndex;
    }
    calendaAlertPickC.selDate = date;
    calendaAlertPickC.isStart = (self.selIndex == 1) ? NO : YES;
    __weak TDCalendaAlertPickC *weakCalendaCarDatePicker= calendaAlertPickC;
    calendaAlertPickC.pickerViewCancleBtnBlock = ^{
        [weakCalendaCarDatePicker removeFromParentViewController];
        [weakCalendaCarDatePicker.view removeFromSuperview];
        //没有记录时间的话
        if (weakSelf.selIndex == 0) {
             //肯定不是同一天
            [weakSelf.calendar deselectDate:date];

        }else {
             //肯定不是同一天
            [weakSelf.calendar deselectDate:date];
        }
    };
    
    
    // MARK: - 确定按钮点击时间
    calendaAlertPickC.pickerViewSureBtnBlock = ^(NSString *hourStr, NSString *minStr, NSString *hourMinStr,NSInteger hourIndex,NSInteger minIndex) {
        
        [weakCalendaCarDatePicker removeFromParentViewController];
        [weakCalendaCarDatePicker.view removeFromSuperview];
        
        if (weakSelf.selIndex == 0) {
            
            //吧上次选中的清空
            if (weakSelf.startSelDate) {
                [weakSelf.calendar deselectDate:weakSelf.startSelDate];
            }
            if (weakSelf.endSelDate) {
                [weakSelf.calendar deselectDate:weakSelf.endSelDate];
            }
            
            //肯定不是同一天
            weakSelf.startSelDate = date;
            weakSelf.endSelDate = nil;
            
            NSString *tmpMonthStr = [[YXDateHelpObject manager] getCurentTime:@"M月dd日" dateN:date];
            weakSelf.topShowStartTitleStr = [NSString stringWithFormat:@"%@ %@",tmpMonthStr,hourMinStr];
            [AppSetting shareAppSetting].startCalendaHourIndex = hourIndex;
            [AppSetting shareAppSetting].startCalendaMinIndex = minIndex;
            weakSelf.topShowEndTitleStr = nil;
            [AppSetting shareAppSetting].endCalendaHourIndex = 0;
            [AppSetting shareAppSetting].endCalendaMinIndex = 0;
            
            weakSelf.selIndex = 1;
            [weakSelf setGetBackStatus:weakSelf.selIndex];
        }
        
        else {
            if (weakSelf.endSelDate) {
                [weakSelf.calendar deselectDate:weakSelf.endSelDate];
            }
            //肯定不是同一天
            weakSelf.endSelDate = date;
            
            NSString *tmpMonthStr = [[YXDateHelpObject manager] getCurentTime:@"M月dd日" dateN:date];
            weakSelf.topShowEndTitleStr = [NSString stringWithFormat:@"%@ %@",tmpMonthStr,hourMinStr];
            [AppSetting shareAppSetting].endCalendaHourIndex = hourIndex;
            [AppSetting shareAppSetting].endCalendaMinIndex = minIndex;
            [weakSelf setTopTitle];
        }
        [weakSelf.calendar reloadData];
    };
    
    [self addChildViewController:calendaAlertPickC];
    [self.view addSubview:calendaAlertPickC.view];
    calendaAlertPickC.view.frame = CGRectMake(0, Height, Width, Height);
    
    [UIView animateWithDuration:0.1f animations:^{
        calendaAlertPickC.view.frame = CGRectMake(0, 0, Width, Height);
    } completion:^(BOOL finished) {
    }];
}


// MARK: - 取消选中点击时间--------同一天的😁😀 头有点晕,为啥要这样的逻辑,麻蛋头疼
- (void)desChooseHourMinDate:(NSDate *)date {
    [self.calendar selectDate:date];
    self.shouldSel = NO;
    __weak typeof(self) weakSelf = self;
    //最后点击的是取消还是选中状态
    TDCalendaAlertPickC *calendaAlertPickC = [[TDCalendaAlertPickC alloc] init];
    if (self.selIndex == 1) {
        calendaAlertPickC.hourIndex = [AppSetting shareAppSetting].endCalendaHourIndex;
        calendaAlertPickC.minIndex = [AppSetting shareAppSetting].endCalendaMinIndex;
    }else {
        calendaAlertPickC.hourIndex = [AppSetting shareAppSetting].startCalendaHourIndex;
        calendaAlertPickC.minIndex = [AppSetting shareAppSetting].startCalendaMinIndex;
    }
    calendaAlertPickC.selDate = date;
    calendaAlertPickC.isStart = (self.selIndex == 1) ? NO : YES;
    __weak TDCalendaAlertPickC *weakCalendaCarDatePicker= calendaAlertPickC;
    calendaAlertPickC.pickerViewCancleBtnBlock = ^{
        [weakCalendaCarDatePicker removeFromParentViewController];
        [weakCalendaCarDatePicker.view removeFromSuperview];
        
        //判断如果是同一天  并且
        if (weakSelf.selIndex == 0) {
            //不管选择的
            //如果继续选择的是开始时间
            if (weakSelf.startSelDate && [[YXDateHelpObject manager] isSameDate:weakSelf.startSelDate AnotherDate:date]) {
                return;
            }
            //选择完还车后回来反向选择开始时间
            if (weakSelf.endSelDate && [[YXDateHelpObject manager] isSameDate:weakSelf.endSelDate AnotherDate:date]) {
                return;
            }
        }else {
            
        }
        
    };
    
    // MARK: - 确定按钮点击时间
    calendaAlertPickC.pickerViewSureBtnBlock = ^(NSString *hourStr, NSString *minStr, NSString *hourMinStr,NSInteger hourIndex,NSInteger minIndex) {
        [weakCalendaCarDatePicker removeFromParentViewController];
        [weakCalendaCarDatePicker.view removeFromSuperview];
        
        if (weakSelf.selIndex == 0) {
            
            //如果继续选择的是开始时间-----这种情况不可能出现----想错了-----
            if (weakSelf.startSelDate && [[YXDateHelpObject manager] isSameDate:weakSelf.startSelDate AnotherDate:date]) {
                [weakSelf.calendar deselectDate:weakSelf.endSelDate];
                
                //肯定不是同一天
                weakSelf.startSelDate = date;
                weakSelf.endSelDate = nil;
                weakSelf.topShowEndTitleStr = nil;
                weakSelf.selIndex = 1;
                
                NSString *tmpMonthStr = [[YXDateHelpObject manager] getCurentTime:@"M月dd日" dateN:date];
                weakSelf.topShowStartTitleStr = [NSString stringWithFormat:@"%@ %@",tmpMonthStr,hourMinStr];
                [AppSetting shareAppSetting].startCalendaHourIndex = hourIndex;
                [AppSetting shareAppSetting].startCalendaMinIndex = minIndex;
                [AppSetting shareAppSetting].endCalendaHourIndex = 0;
                [AppSetting shareAppSetting].endCalendaMinIndex = 0;
                [weakSelf setGetBackStatus:weakSelf.selIndex];
            }
            //肯定是同一天的话
            //选择完还车后回来反向选择开始时间
            if (weakSelf.endSelDate && [[YXDateHelpObject manager] isSameDate:weakSelf.endSelDate AnotherDate:date]) {
                
                [weakSelf.calendar deselectDate:weakSelf.startSelDate];
                
                //肯定不是同一天
                weakSelf.startSelDate = date;
                weakSelf.endSelDate = nil;
                weakSelf.topShowEndTitleStr = nil;
                weakSelf.selIndex = 1;
                
                NSString *tmpMonthStr = [[YXDateHelpObject manager] getCurentTime:@"M月dd日" dateN:date];
                weakSelf.topShowStartTitleStr = [NSString stringWithFormat:@"%@ %@",tmpMonthStr,hourMinStr];
                [AppSetting shareAppSetting].startCalendaHourIndex = hourIndex;
                [AppSetting shareAppSetting].startCalendaMinIndex = minIndex;
                weakSelf.topShowEndTitleStr = nil;
                [AppSetting shareAppSetting].endCalendaHourIndex = 0;
                [AppSetting shareAppSetting].endCalendaMinIndex = 0;
                [weakSelf setGetBackStatus:weakSelf.selIndex];
            }
        }else {
            
            //肯定是同一天的
            if (weakSelf.endSelDate && [[YXDateHelpObject manager] isSameDate:weakSelf.endSelDate AnotherDate:date]) {
                weakSelf.endSelDate = date;
                NSString *tmpMonthStr = [[YXDateHelpObject manager] getCurentTime:@"M月dd日" dateN:date];
                weakSelf.topShowEndTitleStr = [NSString stringWithFormat:@"%@ %@",tmpMonthStr,hourMinStr];
                
                [AppSetting shareAppSetting].endCalendaHourIndex = hourIndex;
                [AppSetting shareAppSetting].endCalendaMinIndex = minIndex;
                
                [weakSelf setTopTitle];
            }
            
        }
        [weakSelf.calendar reloadData];
        weakSelf.shouldSel = YES;
    };
    
    [self addChildViewController:calendaAlertPickC];
    [self.view addSubview:calendaAlertPickC.view];
    calendaAlertPickC.view.frame = CGRectMake(0, Height, Width, Height);
    
    [UIView animateWithDuration:0.12f animations:^{
        calendaAlertPickC.view.frame = CGRectMake(0, 0, Width, Height);
    } completion:^(BOOL finished) {
    }];
}

// MARK: - 清除按钮点击时间------
- (IBAction)clearBtnClick:(UIButton *)sender {
    [self.calendar deselectDate:[NSDate date]];
    if (self.startSelDate) {
        [self.calendar deselectDate:self.startSelDate];
    }
    if (self.endSelDate) {
       [self.calendar deselectDate:self.endSelDate];
    }
    self.startSelDate = nil;
    self.endSelDate = nil;
    self.selIndex = 0;

    self.topShowStartTitleStr = nil;
    self.topShowEndTitleStr = nil;
    [AppSetting shareAppSetting].startCalendaMinIndex = 0;
    [AppSetting shareAppSetting].startCalendaHourIndex = 0;
    [AppSetting shareAppSetting].endCalendaMinIndex = 0;
    [AppSetting shareAppSetting].endCalendaHourIndex = 0;
    [self setGetBackStatus:self.selIndex];
    [self.calendar reloadData];

}

// MARK: - 取车穿换车按钮点击事件
- (IBAction)getOrRebackCarBtnClick:(UIButton *)sender {
    if (sender.tag == 100) {
        //
        if (self.selIndex == 0) {
            return;
        }
        //点击的左边的
        self.selIndex = 0;
    }else if(sender.tag == 200){
        //点击的右边的----
        if (self.selIndex == 1) {
            return;
        }
        
        if (!self.startSelDate) {
            [self setNoticeText:@"请先选择取车时间"];
            return;
        }
        
        self.selIndex = 1;
    }
    
    [self setGetBackStatus:self.selIndex];
    [self.calendar reloadData];
}

#pragma mark - FSCalendarDataSource开始加载调用方法--------------
- (FSCalendarCell *)calendar:(FSCalendar *)calendar cellForDate:(NSDate *)date atMonthPosition:(FSCalendarMonthPosition)monthPosition
{
    
    TDDiyShowCalehdaCell *cell = [calendar dequeueReusableCellWithIdentifier:@"cell" forDate:date atMonthPosition:monthPosition];
    [self configureCell:cell forDate:date atMonthPosition:monthPosition];
    return cell;
}


- (NSDate *)minimumDateForCalendar:(FSCalendar *)calendar
{
    return self.minimumDate;
}

- (NSDate *)maximumDateForCalendar:(FSCalendar *)calendar
{
    return self.maximumDate;
}

- (NSString *)calendar:(FSCalendar *)calendar titleForDate:(NSDate *)date
{
    if ([[YXDateHelpObject manager] isSameDate:[NSDate date] AnotherDate:date]) {
        return @"今";
    }
    if (self.startSelDate && [[YXDateHelpObject manager] isSameDate:date AnotherDate:self.startSelDate]) {
        return @"取";
    }
    if (self.endSelDate && [[YXDateHelpObject manager] isSameDate:date AnotherDate:self.endSelDate]) {
        return @"还";
    }
    return nil;
}

- (void)calendar:(FSCalendar *)calendar willDisplayCell:(FSCalendarCell *)cell forDate:(NSDate *)date atMonthPosition:(FSCalendarMonthPosition)monthPosition
{
   
}




// MARK: - 设置价格--------------------------这个地方会很卡-------------
- (NSString *)calendar:(FSCalendar *)calendar subtitleForDate:(NSDate *)date
{
    return [self configureCellForDate:date];// @"测试";
}

#pragma mark - FSCalendarDelegate
- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date atMonthPosition:(FSCalendarMonthPosition)monthPosition
{
    [self chooseHourMinDate:date];
    NSLog(@"did select %@",[self.dateFormatter stringFromDate:date]);
}

- (void)calendar:(FSCalendar *)calendar didDeselectDate:(NSDate *)date atMonthPosition:(FSCalendarMonthPosition)monthPosition {
    [self desChooseHourMinDate:date];

}


- (void)calendarCurrentPageDidChange:(FSCalendar *)calendar
{
    NSLog(@"did change page %@",[self.dateFormatter stringFromDate:calendar.currentPage]);
}


// MARK: - 设置价格--------------------------这个地方会很卡-------------
- (NSString *)configureCellForDate:(NSDate *)date
{
    NSString *dateStr = [[YXDateHelpObject manager] getStrFromDateFormat:@"yyyy-MM-dd" Date:date];
//    NSString *currentDateStr = [[YXDateHelpObject manager] getStrFromDateFormat:@"yyyy-M-dd" Date:[NSDate date]];
    if (self.allSchedulelist.count == 0) {
        return @"";
    }else {
        TDCalendaShowModel *firstShowModel = self.allSchedulelist.firstObject;
        TDCalendaShowModel *lastShowModel = self.allSchedulelist.lastObject;
        if ([YXDateHelpObject compareDate:dateStr withDate:firstShowModel.workday] == 1 ||  [YXDateHelpObject compareDate:dateStr withDate:lastShowModel.workday] == -1) {
            return @"";
        }else{
            
            if (self.selIndex == 0) {
                self.tmpAllArray = self.allSchedulelist.mutableCopy;
                self.tmpAllArrayDic = self.allSchedulelistStatusDic;
            }else {
                self.tmpAllArray = self.schedulelist.mutableCopy;
                self.tmpAllArrayDic = self.schedulelistStatusDic;
            }
            if (![self isCanUseDateStr:dateStr dateArrayDic:self.tmpAllArrayDic]) {
                return @"";
            }
            NSMutableDictionary *mutaDic = self.allSchedulelistPriceDic;
            if (self.selIndex == 0) {
                mutaDic = self.allSchedulelistPriceDic;
            }else {
                mutaDic = self.schedulelistPriceDic;
            }
            NSString *price = [mutaDic objectForKey:dateStr];
            return price;
        }
    }
    return @"";
}

// MARK: - 设置可以点击和不可以点击状态------
- (void)configureCell:(FSCalendarCell *)cell forDate:(NSDate *)date atMonthPosition:(FSCalendarMonthPosition)monthPosition
{
    
    TDDiyShowCalehdaCell *diyCell = (TDDiyShowCalehdaCell *)cell;
    NSString *dateStr = [[YXDateHelpObject manager] getStrFromDateFormat:@"yyyy-MM-dd" Date:date];
    NSString *currentDateStr = [[YXDateHelpObject manager] getStrFromDateFormat:@"yyyy-MM-dd" Date:[NSDate date]];

    if (self.selIndex == 0) {
        self.tmpAllArray = self.allSchedulelist.mutableCopy;
        self.tmpAllArrayDic = self.allSchedulelistStatusDic;
    }else {
        self.tmpAllArray = self.schedulelist.mutableCopy;
        self.tmpAllArrayDic = self.schedulelistStatusDic;
    }
    
    if (self.tmpAllArray.count == 0) {
        diyCell.isCanUse = NO;
    }else {
        TDCalendaShowModel *firstShowModel = self.tmpAllArray.firstObject;
        TDCalendaShowModel *lastShowModel = self.tmpAllArray.lastObject;
        if ([YXDateHelpObject compareDate:dateStr withDate:firstShowModel.workday] == 1 ||  [YXDateHelpObject compareDate:dateStr withDate:lastShowModel.workday] == -1) {
            diyCell.isCanUse = NO;
        }else{
            
            diyCell.selIndex = self.selIndex;
//            <1表示前面的大于后面的
            if ([YXDateHelpObject compareDate:dateStr withDate:currentDateStr] < 1) {
                // MARK: - 修改了这个地方------
                if ([self isCanUseDateStr:dateStr dateArrayDic:self.tmpAllArrayDic]) {
                    diyCell.isCanUse = YES;
                }else {
                    diyCell.isCanUse = NO;
                }
                if (self.selIndex == 0) {
                    NSString *isCanPick = [self.allSchedulelistPicStatusDic objectForKey:dateStr];
                    diyCell.isCanPick = [isCanPick isEqualToString:@"1"];
                }else {
                    NSString *isCanReturn = [self.schedulelistReturnStatusDic objectForKey:dateStr];
                    diyCell.isCanReturn = [isCanReturn isEqualToString:@"1"];
                }
            }
        }
    }
    
}


- (BOOL)isCanUseDateStr:(NSString *)dateStr dateArrayDic:(NSMutableDictionary *)dateArrayDic {
    if (self.selIndex == 0) {
        NSString *status = [dateArrayDic objectForKey:dateStr];
        if ([status isEqualToString:@"1"]) {
            return YES;
        }
        return NO;
    }else {
        NSString *status = [dateArrayDic objectForKey:dateStr];
        if ([status isEqualToString:@"1"]) {
            return YES;
        }
        return NO;
    }
    return NO;
}


- (BOOL)isContainDateStr:(NSString *)dateStr dateArray:(NSArray *)dateArray {
    for (TDCalendaShowModel *calendatShowModel in dateArray) {
        if ([YXDateHelpObject compareDate:dateStr withDate:calendatShowModel.workday] == 1) {
            if (self.selIndex == 0) {
                if ([calendatShowModel.status isEqualToString:@"1"]) {
                    return YES;
                }
                return NO;
            }
            else {
                if ([calendatShowModel.returnstatus isEqualToString:@"1"]) {
                    return YES;
                }
                return NO;
            }
        }
    }
    return NO;
}

// MARK: - 加载数据
- (void)loadData {
    [self loadLocalData];
}
// MARK: - 本地数据
- (void)loadLocalData {
    self.selIndex = 0;//代表选择的开始位置-------
    NSMutableDictionary *allSchedulelistPriceDic = [[NSMutableDictionary alloc] init];
    NSMutableDictionary *allSchedulelistStatusDic = [[NSMutableDictionary alloc] init];
    NSMutableDictionary *allSchedulelistPicStatusDic = [NSMutableDictionary new];
    for (TDCalendaShowModel *showModel in self.allSchedulelist) {
        [allSchedulelistPriceDic setObject:showModel.price forKey:showModel.workday];
        [allSchedulelistStatusDic setObject:showModel.status forKey:showModel.workday];
        [allSchedulelistPicStatusDic setObject:showModel.pick forKey:showModel.workday];
    }
    self.allSchedulelistPriceDic = allSchedulelistPriceDic;
    self.allSchedulelistStatusDic = allSchedulelistStatusDic;
    self.allSchedulelistPicStatusDic = allSchedulelistPicStatusDic;
    [self setGetBackStatus:NO];
}

// MARK: - 获取网络数据-----
- (void)loadNetData {
    __weak typeof(self) weakSelf = self;
    [self progressHUDShowWithText:nil];
    NSString *pickupdayStr = [[YXDateHelpObject manager] getStrFromDateFormat:@"yyyy-MM-dd" Date:self.startSelDate];
    NSDictionary *paradic = @{@"carid":_detailCarModel.carid,
                              @"pickupday":pickupdayStr
                              };
    [NetWorkRequest postNetRequestData:IsReturndayCanUse parmeters:paradic response:^(NSDictionary *response) {
        if (response) {
            [weakSelf progressHUDHideImmediately];
            weakSelf.schedulelist = [NSArray yy_modelArrayWithClass:[TDCalendaShowModel class] json:response[@"data"][@"daylist"]];
            NSMutableDictionary *schedulelistPriceDic = [[NSMutableDictionary alloc] init];
            NSMutableDictionary *schedulelistStatusDic = [[NSMutableDictionary alloc] init];
            NSMutableDictionary *schedulelistReturnStatusDic = [[NSMutableDictionary alloc] init];
            for (TDCalendaShowModel *showModel in weakSelf.schedulelist) {
                [schedulelistPriceDic setObject:[HelpObject changeNull:showModel.price] forKey:showModel.workday];
                [schedulelistStatusDic setObject:showModel.status forKey:showModel.workday];
                [schedulelistReturnStatusDic setObject:showModel.returnstatus forKey:showModel.workday];
            }
            for (NSString *workday in schedulelistPriceDic.allKeys) {
                NSString *price = [weakSelf.allSchedulelistPriceDic objectForKey:workday];
                [schedulelistPriceDic setObject:price forKey:workday];
            }
            weakSelf.schedulelistPriceDic = schedulelistPriceDic;
            weakSelf.schedulelistStatusDic = schedulelistStatusDic;
            weakSelf.schedulelistReturnStatusDic = schedulelistReturnStatusDic;
            [weakSelf.calendar reloadData];
        }else {
            [weakSelf progressHUDHideImmediately];
        }
    } netError:^(NSError *error) {
        [weakSelf progressHUDShowWithCompleteText:nil isSucceed:NO];
    }];
}

- (void)setGetBackStatus:(BOOL)isRight {
    if (self.selIndex == 1) {
        [self loadNetData];
    }
    if (!isRight) {
        self.lbe_getCarDes.textColor = [UIColor colorWithHex:0xbff0021];
        self.lbe_getCarDetail.textColor = [UIColor colorWithHex:0xbff0021];
        self.bottomView_getCar.hidden = NO;
        
        self.lbe_rebackCarDes.textColor = [UIColor blackColor];
        self.lbe_rebackCarDetail.textColor = [UIColor lightGrayColor];
        self.bottomVIew_rebackCar.hidden = YES;
    }else {
        self.lbe_rebackCarDes.textColor = [UIColor colorWithHex:0xbff0021];
        self.lbe_rebackCarDetail.textColor = [UIColor colorWithHex:0xbff0021];
        self.bottomVIew_rebackCar.hidden = NO;
        
        self.lbe_getCarDes.textColor = [UIColor blackColor];
        self.lbe_getCarDetail.textColor = [UIColor lightGrayColor];
        self.bottomView_getCar.hidden = YES;
    }
    self.lbe_getCarDetail.text = [HelpObject isBlankString:_topShowStartTitleStr] ? @"请选择取车时间": _topShowStartTitleStr;
    self.lbe_rebackCarDetail.text = [HelpObject isBlankString:_topShowEndTitleStr] ? @"请选择还车时间" : _topShowEndTitleStr;
}

- (void)setTopTitle {
    self.lbe_getCarDetail.text = [HelpObject isBlankString:_topShowStartTitleStr] ? @"请选择取车时间": _topShowStartTitleStr;
    self.lbe_rebackCarDetail.text = [HelpObject isBlankString:_topShowEndTitleStr] ? @"请选择还车时间" : _topShowEndTitleStr;
}

- (IBAction)nextBtnClick:(UIButton *)sender {
    if (self.calendaViewShowCBlock) {
        self.calendaViewShowCBlock(self.topShowStartTitleStr, self.topShowEndTitleStr, self.startSelDate, self.endSelDate);
    }
    [self.navigationController popViewControllerAnimated:YES];
}

@end
